package com.fate.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fate.domain.ProdComm;
import com.fate.mapper.ProdCommMapper;
import com.fate.service.ProdCommService;
import com.fate.vo.ProdCommOverview;
import com.netflix.discovery.converters.Auto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("prod/prodComm")
@Api(tags = "商品评论管理接口")
public class ProdCommController {
    @Autowired
    private ProdCommService prodCommService;

    /**
     * 分页查询商品评论
     */
    @GetMapping("page")
    @ApiOperation("分页查询商品评论")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    public ResponseEntity<Page<ProdComm>> findProdCommPage(Page<ProdComm> page, ProdComm prodComm) {
        Page<ProdComm> prodCommPage = prodCommService.findProdCommPage(page,prodComm);
        return ResponseEntity.ok(prodCommPage);
    }

    //----------前台接口 1.评论总览  好评数 总条数 每个级别有多少条
    @GetMapping("prodComn/prodCommData")
    @ApiOperation("根据商品id查询商品总览")
    public ResponseEntity<ProdCommOverview> getProdCommOverview(Long prodId){
      ProdCommOverview prodCommOverview =   prodCommService.getProdCommOverview(prodId);
        return ResponseEntity.ok(prodCommOverview);
    }

    @GetMapping("prodComm/prodCommPageByProd")
    @ApiOperation("根据商品id分页查询商品评论")
    public ResponseEntity<Page<ProdComm>> getProdCommPage(Long prodId, Page<ProdComm> page, Integer evaluate) {
        Page<ProdComm> prodCommPage = prodCommService.getProdCommPage(prodId, page, evaluate);
        return ResponseEntity.ok(prodCommPage);
    }
}
